using UnityEditor;
using UnityEngine;

namespace GameToolkit.Editor
{
    [CustomPropertyDrawer(typeof(EnableEditAttribute))]
    public class EnableEditDrawer : DecoratorDrawer
    {
        public override float GetHeight()
        {
            return 3;
        }

        public override void OnGUI(Rect position)
        {
            if (attribute is EnableEditAttribute)
            {
                var att = (EnableEditAttribute)attribute;
                EditorGUI.BeginDisabledGroup(
                    att.EnableMode == EEnableEditMode.EditorOnly && Application.isPlaying ||
                    att.EnableMode == EEnableEditMode.RuntimeOnly && !Application.isPlaying ||
                    att.EnableMode == EEnableEditMode.Disabled ||
                    att.EnableMode == EEnableEditMode.AlwaysEnabled && true);
            }
            else
            {
                EditorGUI.EndDisabledGroup();
            }
        }
    }
}